package com.controller;

import com.alibaba.fastjson.JSONObject;
import com.common.constant.UpLoadConstant;
import com.common.utils.Result;
import com.entity.Card;
//import com.obs.services.ObsClient;
//import com.obs.services.model.PutObjectResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
@RestController
@RequestMapping("/upload")
public class UpLoadController {

    /**
     * 图片上传
     */
//    @RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
//    public Result fileUpload(@RequestParam(value = "file", required = false) MultipartFile multipartFile) {
//        try {
//            // 创建ObsClient实例
//            ObsClient obsClient = new ObsClient(UpLoadConstant.AK, UpLoadConstant.SK, UpLoadConstant.END_POINT);
//            // 上传文件，注意：上传内容大小不能超过5GB/getTaskStoreByLabel
//            String objectKey = multipartFile.getOriginalFilename();
//            InputStream inputStream = multipartFile.getInputStream();
//            PutObjectResult putObjectResult = obsClient.putObject(UpLoadConstant.BUCKET_NAME, objectKey, inputStream);
//            String url = putObjectResult.getObjectUrl();
////            JSONObject jsonObject = new JSONObject();
////            jsonObject.put("name", objectKey);
////            jsonObject.put("url", url);
//            Card card=new Card();
//            card.setImgUrl(url);
//            inputStream.close();
//            obsClient.close();
//            return Result.success(url);
//        } catch (Exception e) {
////            log.error("{}文件上传失败！", multipartFile.getOriginalFilename());
//            return Result.error("文件上传失败");
//        }
//    }
}
